package com.example.dao;


import com.example.entity.TeacherInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface TeacherInfoDao extends Mapper<TeacherInfo>{

    @Select("select * from teacher_info where name=#{name}")
    TeacherInfo findByName(String name);

    @Select("select * from teacher_info where name=#{name} and password =#{password}")

    TeacherInfo findByNameAndPassword(@Param("name") String name, @Param("password") String password);

    @Select("select * from teacher_info where id=#{id} ")
    TeacherInfo selectById(@Param("id") long id);

    @Update("UPDATE teacher_info " +
            "SET name = #{name}, sex = #{sex}, age = #{age}, zhicheng = #{zhicheng} ,zhuanyeid =#{zhuanyeid} ,password=#{password} " +" "+//这个空格必须加，否则会 报错
            "WHERE id = #{id}")
    void updateById(@Param("id") long id,
                    @Param("name") String name,
                    @Param("password") String password,
                    @Param("sex") String sex,
                    @Param("age") String age,
                    @Param("zhicheng") String zhicheng,
                    @Param("level") int level,
                    @Param("zhuanyeid") Long zhuanyeid
    );

    @Select("select * from teacher_info")
    List<TeacherInfo> selectAllTeacher();

    @Delete("DELETE FROM teacher_info WHERE id = #{id}")
    void deleteById(Long id);

    @Select("select * from teacher_info where name like concat('%',#{name},'%')")
    List<TeacherInfo> findByNamePage(String name);
}
